{extend name="public:layout" /}
{block name="title"}规则管理{/block}
{block name="head"}{/block}
{block name="body"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li><i class="fa fa-hand-o-right"></i> <a href="{:url('index',['utype'=>$Request.param.utype])}">
                    规则管理</a></li>
                <li class="active">规则管理</li>
            </ol>
        </div>
        <div class="ibox-content">
            <div class="toolbar">
                <a class="btn btn-primary" href="{:url('add',['utype'=>$Request.param.utype])}">
                    <i class="fa fa-plus"></i>&nbsp;添加规则
                </a>
                <button class="btn btn-white" type="button"
                        onclick="updateOrder()">
                    <i class="fa fa-sort"></i>更新排序
                </button>
                <a class="btn btn-white" href="{:url('updateCache',['utype'=>$Request.param.utype])}">更新缓存</a>
                <a class="btn btn-white left" href="{:url('copyCate')}">复制规则</a>
            </div>
            <div class="row">
                <div class="col-sm-2">
                    <ul class="nav nav-pills nav-stacked">
                        {foreach $utypeList as $utype}
                        <li {eq name="utype" value="$Request.param.utype" }class="active"{/eq}>
                        <a href="{:url('index',['utype'=>$utype])}">{$utype}</a>
                        </li>
                        {/foreach}
                    </ul>
                </div>
                <div class="col-sm-10">
                    <table class="table table-bordered" id="grid">
                        <tr>
                            <th>#</th>
                            <th width="80">排序</th>
                            <th width="160">规则名称</th>
                            <th>操作</th>
                            <th>附件参数</th>
                            <th>状态</th>
                            <th>图标</th>
                            <th>显示</th>
                            <th width="180">操作</th>
                        </tr>
                        {volist name="authRuleList" id="vo"}
                        <tr id="{$vo.rule_id}" pId="{$vo.rule_pid}">
                            <td>{$vo.rule_id}</td>
                            <td>
                                <input type="text" class="form-control input-sm rule-order"
                                       name="list_order[{$vo.rule_id}]" value="{$vo['rule_sort']}"/>
                            </td>
                            <td>{$vo.title}</td>
                            <td>{$vo.module} {$vo.controller} {$vo.action}</td>
                            <td>{$vo.condition}</td>
                            <td>{$vo.status_text}</td>
                            <td>
                                {notempty name="vo.icon"}
                                <i class="fa {$vo.icon}"></i>
                                {/notempty}
                            </td>
                            <td>{$vo.ismenu_text}</td>
                            <td>
                                <a href="{:url('add',['pid'=>$vo['rule_id'],'utype'=>$vo['utype']])}">添加下级规则</a>
                                <a href="{:url('edit',['rule_id'=>$vo['rule_id'],'utype'=>$vo['utype']])}">编辑</a>
                                <a href="javascript:;" onclick="doAction(this);"
                                   data-msg="此操作不可逆！<br/>确认删除吗？" data-url="{:url('del')}"
                                   data-params="rule_id={$vo.rule_id}&utype={$vo.utype}">删除</a>
                            </td>
                        </tr>
                        {/volist}
                    </table>
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    $(function () {
        In('treetable',function(){
            var option = {
                theme: 'default',
                expandLevel: 2,
                column: 2,
                onSelect: function ($treeTable, id) {
                    window.console && console.log('onSelect:' + id);
                }
            };
            $('.table').treeTable(option);
        })
    });
    //更新排序
    function updateOrder() {
        if ($(".rule-order").length > 0) {
            var data = $(".rule-order").serialize();
            var url = "{:url('updateOrder',['utype'=>$Request.param.utype])}";
            getAjax(url, data, function (data) {
                rePage();
            });
        }
    }
</script>
{/block}